package com.iflysse.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.iflysse.dto.updateUserInfoDto;
import com.iflysse.service.UserInfoService;
import com.iflysse.vo.AjaxResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags = { "修改用户信息" })
@RestController
public class UserInfoController {
	
	@Value("${web.upload-path}")
	private String uploadPath;
	
	@Autowired
	private UserInfoService userInfoService;
	@ApiOperation(value = "修改用户信息")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType = "query", name = "userId", dataType = "String", required=true, value="用户ID"), 
		@ApiImplicitParam(paramType = "query", name = "nickName", dataType = "String", required=true, value="昵称"),
		@ApiImplicitParam(paramType = "query", name = "name", dataType = "int", required=true, value="名字"), 
		@ApiImplicitParam(paramType = "query", name = "gender", dataType = "String", required=true, value="性别"),
		@ApiImplicitParam(paramType = "query", name = "personalSignature", dataType = "String", required=false, value="个性签名"), 
		@ApiImplicitParam(paramType = "query", name = "email", dataType = "String", required=false, value="邮箱"),
		@ApiImplicitParam(paramType = "query", name = "hobby", dataType = "String", required=false, value="兴趣爱好"), 
		@ApiImplicitParam(paramType = "query", name = "role", dataType = "String", required=true, value="角色 1教师/2学生")
	})
	@PostMapping("user/updateUserInfo")
	public Object updateUserInfo(updateUserInfoDto dto) {
		return AjaxResult.getResultBySuccess(userInfoService.updateUserInfo(dto));
	}
	@ApiOperation(value = "修改用户头像")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType = "query", name = "headImagePath", dataType = "MultipartFile", required=true, value="图片"), 
		@ApiImplicitParam(paramType = "query", name = "id", dataType = "String", required=true, value="用户ID"),
		@ApiImplicitParam(paramType = "query", name = "role", dataType = "String", required=true, value="角色 1教师/2学生")
	})
	@PostMapping("user/updateUserHeadImage")
	public Object updateUserHeadImage(MultipartFile headImagePath, String id, String role) {				
		return AjaxResult.getResultBySuccess(userInfoService.updateUserHeadImage(headImagePath, id, role,uploadPath));
	}
	
}
